home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility1 / gs261src.zip / OPER.H < prev    next >
C/C++ Source or Header  |  1993-05-13  |  5KB  |  118 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* oper.h */
  20. /* Definitions for Ghostscript operators */
  21. #include "ostack.h"
  22. #include "opdef.h"
  23. #include "gsutil.h"
  24. #include "iutil.h"
  25.  
  26. /* Structure for initializing variables that hold name constants. */
  27. typedef struct {
  28.     const char _ds *vname;
  29.     ref _ds *pvref;
  30. } names_def;
  31. #define names_def_end {(const char _ds *)0, (ref _ds *)0}
  32. extern void init_names(P1(const names_def _ds *));
  33.  
  34. /* Operand stack manipulation */
  35. /* The most efficient code is different depending on the compiler.... */
  36. #ifdef __TURBOC__            /* stupid compilers */
  37. #define push(n)\
  38.   if ( (op += (n)) > ostop ) return_error(e_stackoverflow); else osp += (n)
  39. #else                    /* reasonable compiler */
  40. #define push(n)\
  41.   if ( (op += (n)) > ostop ) return_error(e_stackoverflow); else osp = op
  42. #endif
  43. /*
  44.  * Note that the pop macro only decrements osp, not op.  For this reason,
  45.  *
  46.  *    >>>    pop should only be used just before returning,    <<<
  47.  *    >>>    or else op must be decremented explicitly.    <<<
  48.  */
  49. #define pop(n) (osp -= (n))
  50. /*
  51.  * Note that the interpreter does not check for operand stack underflow
  52.  * before calling the operator procedure.  There are "guard" entries
  53.  * with invalid types and attributes just below the bottom of the
  54.  * operand stack: if the operator returns with a typecheck error,
  55.  * the interpreter checks for underflow at that time.
  56.  * Operators that don't typecheck their arguments must check for
  57.  * operand stack underflow explicitly; operators that take a variable
  58.  * number of arguments must also check for stack underflow in those cases
  59.  * where they expect more than their minimum number of arguments.
  60.  * (This is because the interpreter can only recognize that a typecheck
  61.  * is really a stackunderflow when the stack has fewer than the
  62.  * operator's declared minimum number of entries.)
  63.  */
  64. #define os_max_nargs 6
  65. extern os_ptr osp_nargs[os_max_nargs];
  66. #define op_nargs_check(nargs) osp_nargs[(nargs) - 1]
  67. #define check_op(nargs)\
  68.   if ( op < op_nargs_check(nargs) ) return_error(e_stackunderflow)
  69.  
  70. /* Check type */
  71. #define check_type(rf,typ)\
  72.   if ( !r_has_type(&rf,typ) ) return_error(e_typecheck)
  73. /* Check for array */
  74. #define check_array_else(rf,err)\
  75.   if ( !r_has_type(&rf, t_array) ) return err
  76. #define check_array(rf) check_array_else(rf, e_typecheck)
  77. /* Check for procedure */
  78. extern int check_proc_failed(P1(const ref *));
  79. #define check_proc(rf)\
  80.   if ( !r_is_proc(&rf) ) return check_proc_failed(&rf);
  81.  
  82. /* Check for read, write, or execute access. */
  83. #define check_access(rf,acc1)\
  84.   if ( !r_has_attr(&rf,acc1) ) return_error(e_invalidaccess)
  85. #define check_read(rf) check_access(rf,a_read)
  86. #define check_type_access(rf,typ,acc1)\
  87.   if ( !r_has_type_attrs(&rf,typ,acc1) )\
  88.     return_error((!r_has_type(&rf,typ) ? e_typecheck : e_invalidaccess))
  89. #define check_read_type(rf,typ) check_type_access(rf,typ,a_read)
  90. #define check_write(rf) check_access(rf,a_write)
  91. #define check_write_type(rf,typ) check_type_access(rf,typ,a_write)
  92. #define check_execute(rf) check_access(rf,a_execute)
  93.  
  94. /* Macro for as yet unimplemented operators. */
  95. /* The if ( 1 ) is to prevent the compiler from complaining about */
  96. /* unreachable code. */
  97. #define NYI(msg) if ( 1 ) return_error(e_undefined)
  98.  
  99. /*
  100.  * If an operator has popped or pushed something on the control stack,
  101.  * it must return o_pop_estack or o_push_estack respectively,
  102.  * rather than 0, to indicate success.
  103.  * It is OK to return o_pop_estack if nothing has been popped,
  104.  * but it is not OK to return o_push_estack if nothing has been pushed.
  105.  *
  106.  * If an operator has suspended the current context and wants the
  107.  * interpreter to call the scheduler, it must return o_reschedule.
  108.  * It may also have pushed or popped elements on the control stack.
  109.  * (This is only used when the Display PostScript option is included.)
  110.  *
  111.  * These values must be positive, and far enough apart from zero and
  112.  * from each other not to tempt a compiler into implementing a 'switch'
  113.  * on them using indexing rather than testing.
  114.  */
  115. #define o_push_estack 3
  116. #define o_pop_estack 8
  117. #define o_reschedule 14
  118.